main(){int t,i,c;char d[10001];scanf("%d",&t);while(t--){scanf("%s",d);c=1;i=0;while(d[++i]!=0)if(d[i]!=d[i-1]){if(c!=1)printf("%d",c);putchar(d[i-1]);c=1;}else c++;if(c!=1)printf("%d",c);printf("%c\n",d[i-1]);}}
